Programming With QuickTime Sprites

| Previous | Chapter Contents | Chapter Top | Next |

Sprite World Functions

This section describes functions that you use to create and manipulate sprite worlds.

NewSpriteWorld

The NewSpriteWorld function creates a new sprite world.

pascal OSErr NewSpriteWorld (SpriteWorld *newSpriteWorld,
                     GWorldPtr destination,
                     GWorldPtr spriteLayer,
                     RGBColor *backgroundColor,
                     GWorldPtr background);
newSpriteWorld
Contains a pointer to a field that is to receive the new sprite world's identifier. On return, this field contains the identifier for the newly created sprite world.
destination
Contains a pointer to a graphics world to be used as the destination.
spriteLayer
Contains a pointer to a graphics world to be used as the sprite layer.
backgroundColor
Contains a pointer to an RGB color to be used as the background color. If you pass a background graphics world to this function by setting the background parameter, you can set this parameter to nil .
background
Contains a pointer to a graphics world to be used as the background. If you pass a background color to this function by setting the backgroundColor parameter, you can set this parameter to nil .

DISCUSSION

You call this function to create a new sprite world with associated destination and sprite layer graphics worlds, and either a background color or a background graphics world. Once created, you can manipulate the sprite world and add sprites to it using other sprite toolbox functions. The sprite world created by this function has an identity matrix. The sprite world does not have a clip shape.

The newSpriteWorld , destination , and spriteLayer parameters are all required. You should specify a background color, a background graphics world, or both. You should not pass nil for both parameters. If you specify both a background graphics world and a background color, the sprite world is filled with the background color before the background sprites are drawn. If no background color is specified, black is the default. If you specify a background graphics world, it should have the same dimensions and depth as the graphics world specified by spriteLayer . If you draw to the graphics worlds associated with a sprite world using standard QuickDraw and QuickTime functions, your drawing is erased by the sprite world's background color.

Before calling NewSpriteWorld , you should call LockPixels on the pixel maps of the sprite layer and background graphics worlds. These graphics worlds must remain valid and locked for the lifetime of the sprite world. The sprite world does not own the graphics worlds that are associated with it; it is the caller's responsibility to dispose of the graphics worlds when they are no longer needed.

RESULT CODES

noErr
0 No error
paramErr
-50 Invalid parameter specified
memFullErr
-108 Not enough memory available
gWorldsNotSameDepthAndSizeErr
-2066 Dimensions and pixel depth of the two graphics worlds do not match

DisposeSpriteWorld

The DisposeSpriteWorld function disposes of a sprite world.

pascal void DisposeSpriteWorld (SpriteWorld theSpriteWorld);
theSpriteWorld
Specifies the sprite world to dispose.

DISCUSSION

You call this function to dispose of a sprite world created by the NewSpriteWorld function. This function also disposes of all of the sprites associated with the sprite world. This function does not dispose of the graphics worlds associated with the sprite world. It is safe to pass nil to this function.

SetSpriteWorldClip

The SetSpriteWorldClip function sets a sprite world's clip shape to the specified region.

pascal OSErr SetSpriteWorldClip (SpriteWorld theSpriteWorld,
                     RgnHandle clipRgn);
theSpriteWorld
Specifies the sprite world for this operation.
clipRgn
Specifies the new clip shape for the sprite world.

DISCUSSION

You call this function to change the clip shape of a sprite world. You may pass a value of nil for the clipRgn parameter to indicate that there is no longer a clip shape for the sprite world. This means that the whole area is drawn.

The clip shape should be specified in the sprite world's source space, the coordinate system of the sprite layer's graphics world before the sprite world's matrix is applied to it. The specified region is owned by the caller and is not copied by this function.

RESULT CODES

noErr
0 No error
paramErr
-50 Invalid parameter specified

SetSpriteWorldMatrix

The SetSpriteWorldMatrix function sets a sprite world's matrix to the specified matrix.

pascal OSErr SetSpriteWorldMatrix (SpriteWorld theSpriteWorld,
                     const MatrixRecord *matrix);
theSpriteWorld
Specifies the sprite world for this operation.
matrix
Contains a pointer to the new matrix for the sprite world.

DISCUSSION

You call this function to change the matrix of a sprite world. You may pass a value of nil for the matrix parameter to set the sprite world's matrix to an identity matrix.

Transformations, including translation, scaling, rotation, skewing, and perspective, are all supported in QuickTime 3.

RESULT CODES

noErr
0 No error
paramErr
-50 Invalid parameter specified

SpriteWorldIdle

The SpriteWorldIdle function allows a sprite world to update its invalid areas.

pascal OSErr SpriteWorldIdle (SpriteWorld theSpriteWorld,
                     long flagsIn,
                     long *flagsOut);
theSpriteWorld
Specifies the sprite world for this operation.
flagsIn
Contains flags describing actions that may take place during the idle.
flagsOut
On return, contains a pointer to flags describing actions that took place during the idle.

DISCUSSION

You call this function to allow a sprite world the opportunity to redraw its invalid areas. This is the only function that causes drawing to occur; you should call it as often as is necessary.

The flagsIn parameter contains flags that describe allowable actions during the idle period. For the default behavior, you should set the value of this parameter to 0. The flagsOut parameter is optional; if you do not need the information returned by this parameter, set the value of this parameter to nil .

Typically, you would make changes in perspective for a number of sprites and then call SpriteWorldIdle to redraw the changed sprites.

RESULT CODES

noErr
0 No error
paramErr
-50 Invalid parameter specified

InvalidateSpriteWorld

The InvalidateSpriteWorld function invalidates a rectangular area of a sprite world.

pascal OSErr InvalidateSpriteWorld (SpriteWorld theSpriteWorld,
                     Rect *invalidArea);
theSpriteWorld
Specifies the sprite world for this operation.
invalidArea
Contains a pointer to the rectangular area that should be invalidated.

DISCUSSION

Typically, your application calls this function when the sprite world's destination window receives an update event. Invalidating an area of the sprite world will cause the area to be redrawn the next time that SpriteWorldIdle is called.

The invalid rectangle pointed to by the invalidArea parameter should be specified in the sprite world's source space, the coordinate system of the sprite layer's graphics world before the sprite world's matrix is applied to it. To invalidate the entire sprite world, pass nil for this parameter.

When you modify sprite properties, invalidation takes place automatically; you do not need to call InvalidateSpriteWorld .

RESULT CODES

noErr
0 No error
paramErr
-50 Invalid parameter specified

SpriteWorldHitTest

The SpriteWorldHitTest function determines whether any sprites are at a specified location in a sprite world.

pascal OSErr SpriteWorldHitTest (SpriteWorld theSpriteWorld,
                     long flags,
                     Point loc,
                     Sprite *spriteHit);
theSpriteWorld
Specifies the sprite world for this operation.
flags
Specifies flags to control the hit testing operation. These flags are described in "Flags for Sprite Hit Testing" .
loc
Specifies a point in the sprite world's display space to test for the existence of a sprite.
spriteHit
Contains a pointer to a field that is to receive a sprite identifier. On return, this field contains the identifier of the frontmost sprite at the location specified by loc . If no sprite exists at the location, the function sets the value of this parameter to nil .

DISCUSSION

You call this function to determine whether any sprites exist at a specified location in a sprite world's display coordinate system. If you are drawing the sprite world in a window, you should call GlobalToLocal to convert the location to your window's local coordinate system before passing it to SpriteWorldHitTest .

You use the spriteHitTestBounds and spriteHitTestImage flags in the flags parameter to control the hit test operation. Set the spriteHitTestBounds flag to check if there has been a hit anywhere within the sprite's bounding box. Set the spriteHitTestImage flag to check if there has been a hit anywhere within the sprite image.

A hit testing operation does not occur unless you pass one of the flags, either SpriteHitTestBound or SpriteHitTestImage . You can add other flags as needed.

RESULT CODES

noErr
0 No error
paramErr
-50 Invalid parameter specified

DisposeAllSprites

The DisposeAllSprites function disposes all sprites associated with a sprite world.

pascal void DisposeAllSprites (SpriteWorld theSpriteWorld);
theSpriteWorld
Specifies the sprite world for this operation.

DISCUSSION

This function calls the DisposeSprite function for each sprite associated with the sprite world.


© 1998 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |